package com.itheima;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) throws IOException, TimeoutException {
        //1.创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        //2. 设置参数
        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();
        /*queueDeclare(String queue, boolean durable, boolean exclusive, boolean autodelete, Map<String, Object> arguments)
        * 1.queue:队列名称
        * 2.durable:是否持久化，当mq重启时还在
        * 3.exclusive:是否独占，只能有一个消费者监听此队列
        *               当Connecton关闭时，是否删除队列
        * 4.autodelete:是否自动删除。当没有consumer时自动删除
        * 5.arguments:参数
        * */
        channel.queueDeclare("hello-word",true,false,false,null);
        String body="hello-rabbitmq";
        /*basicPublish(String exchange, String routingkey,BasicProperties props, byte[] body)
         1.exchange:交换机名称，简单模式下默认
         2.routingkey：路由名称
         3.props：配置信息
         4.body：发送消息数据
        */
        //6发送消息
        channel.basicPublish("","hello-word",null,body.getBytes());
        channel.close();
        connection.close();
    }
}
